<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head lang="zh-cn">
    <meta charset="<?php $CfgPara->database["charset"] ?>"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Sneaker</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" type="text/css" href="/css/amazeui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/css/app.css"/>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/amazeui.min.js"></script>
    <script type="text/javascript">
        function file_check() {
            var file = document.getElementById('work_img_upload').files[0];
            if (file) {
                var file_size = Math.round(file.size * 100 / 1024) / 100;
                if (file_size >= 1024) {
                    alert('图片不能大于1M');
                    return false;
                }
                else return true;
            } else {
                return false;
            }
        }
        //作品上传图片
        function work_edit_img_upload() {
            if (file_check() === true) {
                document.getElementById("work_img_form").submit();
            }
        }
        function work_edit_remove_img() {
            var $work_img_count = $("#work_edit_img_index");
            var count = $work_img_count.text();
            if (count == 1) {
                alert('已经是最后一张图片了');
                return;
            }
            if (confirm("确定删除当前照片吗")) {
                var slider = $('#slider').data('flexslider');
                //alert(slider.currentSlide);
                var slider_index = slider.currentSlide;

                $.ajax({
                    url: '/index.php',
                    type: 'POST',
                    data: {
                        controller: 'work_edit',
                        work_img: 'dele',
                        work_img_index: slider_index
                    },
                    timeout: 5000,
                    error: function () {
                        alert('无法连接服务器！');
                    },
                    success: function (result) {
                        if (result == 1) {
                            slider.removeSlide(slider_index);
                            $work_img_count.text(count - 1);
                        } else {
                            alert(result);
                        }
                    }
                });
            }
        }
    </script>
</head>
<body>
<?php if (!isset($workImg) || $workImg === false) { //如果当前没有图片被上传 使用原始?>
    <form id="work_img_form"
          action="<?php echo $CfgPara->httproot ?>/index.php?controller=work_edit"
          method="post" enctype="multipart/form-data">
        <div class="am-form-group am-form-file" style="margin:0px">
            <div class="am-vertical-align" style="width:100%;height:310px;text-align:center;">
                <a class="am-vertical-align-middle am-icon-btn am-secondary am-icon-photo"></a>
                <input id="work_img_upload" name="work_img_upload" type="file" onchange="work_edit_img_upload()">
            </div>
        </div>
    </form>
<?php } else {
    $workImgCount = 0; ?>
    <div
            id="slider"
            data-am-widget="slider"
            class="am-slider am-slider-default"
            data-am-slider="{slideshow: false}"
            style="margin:0px">
        <ul class="am-slides">
            <?php
            foreach ($workImg as $imgName) {
                if (isset($imgName) && $imgName != '') {
                    echo "<li><img src='/works_pic/{$imgName}'></li>";
                    $workImgCount++;
                }
            }
            ?>
        </ul>
    </div>
    <div style="padding:15px 10px 0px 10px">
        <div class="am-fl">
            <form id="work_img_form" action="<?php echo $CfgPara->httproot ?>/index.php?controller=work_edit"
                  method="post"
                  enctype="multipart/form-data">
                <div class="am-form-group am-form-file" style="margin:0px">
                    <a class="am-vertical-align-middle am-icon-btn am-secondary am-icon-photo"></a>
                    <input id="work_img_upload" name="work_img_upload" type="file" onchange="work_edit_img_upload()">
                </div>
            </form>
        </div>
        <div class="am-fl">
            <a class="am-vertical-align-middle am-icon-btn am-danger am-icon-minus-square-o"
               onclick="work_edit_remove_img()">
            </a>
        </div>
        <div class="am-fr">
            <span id="work_edit_img_index"><?php echo $workImgCount ?></span>/9
        </div>
    </div>
<?php } ?>
</body>
</html>